package com.wx.daoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import org.junit.runner.Request;

import com.mysql.jdbc.interceptors.SessionAssociationInterceptor;
import com.wx.dao.MyOrderDao;
import com.wx.model.MyOrder;
import com.wx.model.Order;
import com.wx.util.DBUtil;

public class MyOrderDaoImpl implements MyOrderDao {

	@Override
	public List<MyOrder> findMyOrder(int userid) throws Exception {
		List<MyOrder> list = new ArrayList<>();
		Connection conn = DBUtil.getConnection();
		PreparedStatement ps = conn.prepareStatement("select b.bookname,o.ordertime,o.bookcount,o.count from books b,orders o where userid=? and o.bookid=b.bookid");
		ps.setInt(1, userid);
		ResultSet rs = ps.executeQuery();
		while(rs.next()){
			MyOrder order = new MyOrder();
			order.setBookname(rs.getString("bookname"));
			order.setDate(rs.getTimestamp("ordertime"));
			order.setBookcount(rs.getInt("bookcount"));
			order.setCount(rs.getDouble("count"));
			list.add(order);
		}
		return list;
	}

}
